<?php
/**
*
* @package ppkBB3cker
* @version $Id: taself1.php 1.000 2009-02-13 12:02:00 PPK $
* @copyright (c) 2008 PPK
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

$uploaded ? $upthis=my_int_val($uploaded - $attachment['uploaded']) : '';
$shadowupthis=$upthis;

$downloaded ? $downthis=my_int_val($downloaded - $attachment['downloaded']) : '';
$shadowdownthis=$downthis;

$updatesnatch[]="uploadoffset='{$upthis}'";
$updatesnatch[]="downloadoffset='{$downthis}'";

$ppkbb_tcrewr_updown[0] ? $user['upload']=$ppkbb_tcrewr_updown[0] : '';
$ppkbb_tcrewr_updown[1] ? $user['free']=$ppkbb_tcrewr_updown[1] : '';

if($upthis)
{
	$updatesnatch[]='uploaded=uploaded+'.$upthis;
	$updatepeers[]='uploaded=uploaded+'.$upthis;

	$ppkbb_tcignored_upload=my_int_val($ppkbb_tcignored_upload);
	if(($ppkbb_tcignored_upload && $upthis > $ppkbb_tcignored_upload * 1024 * 1024 * 1024) || ($unregtorr && $ppkbb_tcallow_unregtorr==2))
	{
		//$upthis=0;
	}
	else
	{
		$user_upthis=$upthis;
		if($userid==$user['poster_id'])
		{
			$updateuser[]='user_uploaded_self=user_uploaded_self+'.$user_upthis;
		}
		if($userid!=$user['poster_id'] && $ppkbb_tcbonus_value > 0 && $rights[6] && $user['size'] > $ppkbb_tcbonus_fsize * 1024 * 1024)
		{
			/*$sql = 'SELECT bonus_count FROM '.TRACKER_SNATCHED_TABLE." WHERE userid='{$userid}' AND torrent='{$torrentid}' LIMIT 1";
			$result=my_sql_query($sql);
			$user_bonus=mysql_fetch_array($result);
			mysql_free_result($result);

			$bonus_value = ($upthis + $user_bonus['bonus_count']) / 1024 / 1024;
			$bonus_value = intval($bonus_value / $ppkbb_tcbonus_upvalue);

			if($bonus_value > 0)
			{
				$bonus_left = intval(($upthis + $user_bonus['bonus_count']) - ($bonus_value * $ppkbb_tcbonus_upvalue * 1024 * 1024));
				$bonus_left ? $updatesnatch[] =  "bonus_count = '{$bonus_left}'" : '';
				$updateuser[]='user_bonus=user_bonus + '. ($bonus_value * $ppkbb_tcbonus_value);
			}
			else
			{
				$upthis ? $updatesnatch[] = 'bonus_count = bonus_count + '.$upthis : '';
			}*/
			$updatesnatch[]='bonus_count=bonus_count+'.$upthis;
		}
		if(($rights[12] || $ppkbb_tcrewr_updown[0]) && $user['upload'])
		{
			$user['upload'] > 250 ? $user['upload']=250 : '';
			$user_upthis=my_int_val($upthis+($upthis*$user['upload'])/100);
		}
		$updateuser[]='user_uploaded=user_uploaded+'.$user_upthis;
	}
}

if($downthis)
{
	$updatesnatch[]='downloaded=downloaded+'.$downthis;
	$updatepeers[]='downloaded=downloaded+'.$downthis;

	if($unregtorr && $ppkbb_tcallow_unregtorr==2)
	{

	}
	else
	{
	$user_downthis=$downthis;
	if($rights[4] && !$ppkbb_tcrewr_updown[1])
	{
		$user_downthis=0;
	}
	else if($rights[3] && !$ppkbb_tcrewr_updown[1])
	{
		$user_downthis=$downthis/2;
	}
	else
	{
		if($user['free'] && ($rights[5] || $ppkbb_tcrewr_updown[1]))
		{
			$user['free'] > 100 ? $user['free']=100 : '';
			$user_downthis=$downthis*((100-$user['free'])/100);
		}
	}
	$updateuser[]='user_downloaded=user_downloaded+'.$user_downthis;
}
}

$shadowdownthis ? $updateuser[] = 'user_shadow_downloaded = user_shadow_downloaded + '.$shadowdownthis : '';
$shadowupthis ? $updateuser[] = 'user_shadow_uploaded = user_shadow_uploaded + '.$shadowupthis : '';

if ($updateuser)
{
	my_sql_query('UPDATE '. USERS_TABLE .' SET '.implode(', ', $updateuser)." WHERE user_id='{$userid}' LIMIT 1");
}

?>
